﻿using System.Collections.Generic;
using System.Linq;
using Microsoft.Win32;

namespace WindowsAPI.RegistryEx
{
    public static class Macros
    {
        private const string sf_RegPath_HKLM_Software_Autorun = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run\";

        public static void SetAutorun(string ValueName, string Command)
        {
            using(var key = Registry.LocalMachine.OpenSubKey(sf_RegPath_HKLM_Software_Autorun, true))
            {
                key.SetValue(ValueName, Command);
            }
        }

        public static IEnumerable<KeyValuePair<string, string>> GetAutorun()
        {
            using(var key = Registry.LocalMachine.OpenSubKey(sf_RegPath_HKLM_Software_Autorun, false))
            {
                return key.GetValueNames()
                    .Select(name => new KeyValuePair<string, string>(name, (string)key.GetValue(name, "")));
            }
        }
    }
}